<template>
  <li @mouseenter="isShow = true" @mouseleave="isShow = false" :class="{active:isShow}">
    <label>
        <!-- 根据每一个 todo.isOver 的值 来确定是否默认勾选任务 -->
      <input type="checkbox" :checked="todo.isOver" @click="update"/>
      <!-- 渲染 todo.content -->
      <span>{{ todo.content }}</span>
    </label>
    <button class="btn btn-danger" v-show="isShow" @click="delOne">删除</button>
  </li>
</template>

<script>
export default {
  name: "ItemComponent",
  // 接收父组件传递的todo数据，是一个个对象
  props: ["todo",'index','updateIsOver','delTodo'],
  data(){
      return {
          isShow:false,
      }
  },
  methods:{
      update(){
        
          this.updateIsOver(this.index)
      },
      delOne(){
          this.delTodo(this.index)
      }
  }
};
</script>

<style scoped>
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

.active{
    background-color: skyblue;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}
</style>
